#pragma once

#include <cmath>
#include "vector3.h"
#include "polygon_fill_algo.h"
#include "range_fill.h"

class Box3D
{
private:
    float wall_min_[3];
    float wall_max_[3];
    float face_degree_;
    Vector3 center_pos_;  // 中心
public:
    static Box3D* CreateBox3D(const Vector3& pos, const Vector3& scale, const float& face_degree);
    //>> 用于判断 把线段映射到xy平面上后 与 底面平行于xy平面的长方体的底面 是否相交
    static bool IsRayCross2D(const Vector3 & start_pos, const Vector3 & end_pos, const Box3D* box);
    //>> 用于判断 线段 与 底面平行于xy平面的长方体 是否相交
    static bool IsRayCross3D(const Vector3 & start_pos, const Vector3 & end_pos, const Box3D* box);
};

class UtilMath
{
public:
    static void Init();
    static Vector3 RotateAroundPoint(const Vector3 &p, const Vector3 &o, float degree);
    static bool CheckEllipseCollision(const Vector3& self_pos, float self_face, const Vector3& self_scale, const Vector3& from, const Vector3& to);
    static bool CheckEllipseCollisionOld(const Vector3& self_pos, float self_face, const Vector3& self_scale, const Vector3& from, const Vector3& to);
    static bool IsInEllipse(const Vector3& self_pos, float self_face, const Vector3& self_scale, const Vector3& pos);
    static bool CheckCircleCollision(const Vector3& self_pos, float self_face, const Vector3& self_scale, const Vector3& from, const Vector3& to);
    static bool IsInCircle(const Vector3& self_pos, float self_face, const Vector3& self_scale, const Vector3& pos);
    /* 2017.05.18 hechangbing增加注释
    * 判断在center坐标yRot朝向pvecs矩形框是否包含点point
    * 点v：点center到点point的向量反方向旋转yRot度
    * 判断矩形框是否包含点v
    */
    static bool IsInRect(const Vector3& point, const Vector3* pvecs, const Vector3& center, float yRot);

    static float ROSin[721];
    static float ROCos[721];
};

extern "C" int add(int a,int b);
extern "C" int sub(int a,int b);
extern "C" int mul(int a,int b);
extern "C" int dvd(int a,int b);